package demo;

import javafx.animation.ScaleTransition;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.effect.Lighting;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

// 缩放动画
public class ScaleTransitionDemo extends Application {
	private Pane root = new Pane();
	private Rectangle rectangle;
	private ScaleTransition scale;
	
	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage stage) throws Exception {
		
	    rectangle = new Rectangle(100, 100, Color.YELLOW);
	    rectangle.setEffect(new Lighting());
	    rectangle.setLayoutX(150);
	    rectangle.setLayoutY(100);
		root.getChildren().add(rectangle);
	    
		// 动画
		scale = new ScaleTransition(Duration.seconds(1), rectangle);
		scale.setToX(2);	// 宽缩放的倍数
		scale.setToY(2);
		scale.setAutoReverse(true);
		scale.setCycleCount(Timeline.INDEFINITE);
		scale.play();
		
	    Scene scene = new Scene(root, 500, 400);    
	    stage.setScene(scene);
		stage.show();
	}
}
